package com.ficus.road.maintain.service.smartnew;

import com.ficus.road.maintain.core.model.smartnew.SmartTotal;
import com.ficus.road.maintain.dao.smartnew.SmartTotalDao;
import com.ficus.road.maintain.util.MyDateUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author xiawen yang
 * @date 2022/3/3 下午3:01
 */
@Service
@RequiredArgsConstructor
public class SmartTotalService {
    private final SmartTotalDao smartTotalDao;

    public SmartTotal findOneByRoadType(Query query) {
        // todo: 获取智慧决策统计数据
        query.addCriteria(Criteria.where("date").is(MyDateUtil.getYear(new Date()) + ""));
        return smartTotalDao.findOne(query);
    }

    public SmartTotal saveOrUpdate(SmartTotal smartTotal) {
        return smartTotalDao.saveOrUpdate(smartTotal);
    }

    public void deleteAll() {
        smartTotalDao.deleteAll();
    }
}
